package com.biubiushop.jdbc;

import cn.hutool.core.collection.CollUtil;
import com.biubiushop.entity.Commodity;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class EquipmentJdbc {

    @Resource
    JdbcTemplate template;

    public List<Commodity> getCommodity(Integer length) {
        StringBuffer sb = new StringBuffer();
        List<Object> params = CollUtil.newArrayList();

        sb.append("SELECT * ");

        sb.append("FROM commodity ");

        sb.append("WHERE ");
        sb.append("length < ?");
        params.add(length);

        List<Commodity> list = template.query(sb.toString(), params.toArray(),new BeanPropertyRowMapper<Commodity>(Commodity.class));
        return list;
    }


}
